package com.mec.web.y2012.coreservlet;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

public class CookieUtilities {
	
	public static String getCookieValue(HttpServletRequest request, String cookieName, String defaultValue){
		Cookie[] cookies = request.getCookies();
		
		if(null != cookies){
			for(Cookie cookie : cookies){
				if(cookieName.equals(cookie.getName())){
					return cookie.getValue();
				}
			}
		}
		
		//
		return defaultValue;
	}
	
	public static Cookie getCookie(HttpServletRequest request, String cookieName){
		Cookie[] cookies = request.getCookies();
		
		//
		if(null != cookies){
			for(Cookie cookie : cookies){
				if(cookieName.equals(cookie.getName())){
					return cookie;
				}
			}
		}
		//
		return null;
	}
	private static final Logger logger = 
			Logger.getLogger(CookieUtilities.class);

}
